#!/usr/bin/env python
from django.core.management import setup_environ
try:
    import settings # Assumed to be in the same directory.
except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
    sys.exit(1)



if __name__ == '__main__':
    setup_environ(settings)
    v = raw_input('This function well automatic insert 200 random user,are you sure![Y/N]:')
    if not v.lower() == 'y':
        exit()
    from apps.models import User,Language
    from apps.blog.models import Profile,Post
    from utils import formatter,function,mailer,uploader,logs
    import random,traceback

    user_num = 200
    password = function.md5_encode('123123')
    for i in range(1,user_num):
        idx = random.randint(1,200*1000)
        score = random.randint(1,200)
        username = 'user%s' % (idx)

        try:
            user = User(email = '%s@coderblogs.com' % username,password = password,realname=username,score=score,status = 1)
            if user.check().success:
                user.save()

                profile = Profile(user = user,title = '%s\'s weblog' % username,slug = username)
                if profile.check().success:
                    profile.save()

                    print '%s added.' % username
        except:
            print '%s add error.' % username
            logs.write(traceback)

